package com.xinke.juc.sguigu.case02;

import com.xinke.juc.sguigu.util.Sleep;
import lombok.extern.slf4j.Slf4j;

import java.util.concurrent.CompletableFuture;
import java.util.concurrent.ExecutionException;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;

/**
 * @Author：xinke
 * @Date：2025/10/9
 * @Desc: 四个静态方法演示
 */
@Slf4j
public class C03_CompletableFuture_StaticMethod {
    public static void main(String[] args) throws ExecutionException, InterruptedException {
        ExecutorService executorService = Executors.newFixedThreadPool(3);
        CompletableFuture<Void> voidCompletableFuture = CompletableFuture.runAsync(() -> {
            log.info(Thread.currentThread().getName());
            Sleep.seconds(1);
        }, executorService);
        log.info(String.valueOf(voidCompletableFuture.get()));

        CompletableFuture<String> completableFuture = CompletableFuture.supplyAsync(() -> {
            log.info(Thread.currentThread().getName());
            Sleep.seconds(1);
            return "hello CompletableFuture";
        }, executorService);
        log.info(completableFuture.get());

        executorService.shutdown();
    }
}
